package presenter.code.entity;

import utils.Pair;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public enum AccountType implements IAccount {
    Normal("08:56:09.071   登录成功，用户工号=jq008，类型=1", Pattern.compile("(\\d+):(\\d+):\\d+.\\d+   登录成功，用户工号=jq(\\d+)"));

    private final Pattern pattern;

    AccountType(String demo, Pattern pattern) {
        this.pattern = pattern;
    }

    @Override
    public Pattern pattern() {
        return pattern;
    }

    @Override
    public String index(Matcher matcher) {
        return matcher.group(3);
    }

    @Override
    public Pair<String, Boolean> login(Matcher matcher) {
        boolean overtime = false;
        String hourStr = matcher.group(1);
        String minStr = matcher.group(2);
        try {
            float fixedTime = Float.parseFloat(String.format("%s.%s", hourStr, minStr));
            overtime = fixedTime > 10.3;//登录是否超过10:30
        } catch (Exception ex) {
            //ignore
        }
        return new Pair<>(String.format("%s:%s", hourStr, minStr), overtime);
    }
}
